<template>
	<view class="container">
		<view class="list">
			<view class="list_item">
				<view class="left">
					机柜编号
				</view>
				<view class="right">
					<text>{{code}}</text>
				</view>
			</view>
			<view class="list_item">
				<view class="left">
					硬件状态
				</view>
				<view class="right">
					<text>{{state_text}}</text>
					<!-- <image src="/static/img/detail/right.png" mode="widthFix"></image> -->
				</view>
			</view>
			<view class="list_item">
				<view class="left">
					上线时间
				</view>
				<view class="right">
					<text>{{online_time_date}}</text>
				</view>
			</view>
			<view class="list_item">
				<view class="left">
					总收入
				</view>
				<view class="right">
					<text>{{all_income}}</text>
				</view>
			</view>
			<view class="list_item">
				<view class="left">
					帮助电话
				</view>
				<view class="right">
					<text>{{help_phone}}</text>
					<!-- <image src="/static/img/detail/right.png" mode="widthFix"></image> -->
				</view>
			</view>
		</view>

		<view class="list">
			<view class="list_item" @click="editAdd">
				<view class="left">
					机柜名称
				</view>
				<view class="right">
					<!-- <text>{{name}}</text> -->
					<input type="text" value="" v-model="name" @focus="getFocus('name')" @blur="edit('name')" />
				</view>
			</view>

			<!-- <view class="list_item" @click="isChange" style="height: 200upx;"> -->
			<view  class="list_item" style="height: 200upx;">
				<view class="left">
					分段收费
				</view>
				<view class="right">
					<view>
						 {{free_time}}
						<!-- <view>{{free_time}}分钟以内 | 免费</view>
						<view>{{fee_first_time}}分钟 | {{fee_first_money}}元</view>
						<view>每{{fee_time}}分钟 | {{fee_money}}元</view> -->
					</view>
					<!-- <image src="/static/img/detail/right.png" mode="widthFix"></image> -->
				</view>
			</view>
		</view>

		<view class="news" v-if="ischeck">
			<view class="new_item">
				<text></text>
				<input type="number" value="" v-model="free_time" @focus="getFocus('free_time')"
					@blur="edit('free_time')" />
				<text>分钟以内免费</text>
			</view>
			<view class="news_tip">
				第一阶段收费
			</view>
			<view class="new_item">
				<text></text>
				<input type="number" value="" v-model="fee_first_time" @focus="getFocus('fee_first_time')"
					@blur="edit('fee_first_time')" />
				<text>分钟</text>
				<input type="number" value="" v-model="fee_first_money" @focus="getFocus('fee_first_money')"
					@blur="edit('fee_first_money')" />
				<text>元</text>
			</view>
			<view class="news_tip">
				第二阶段收费
			</view>
			<view class="new_item">
				<text>每</text>
				<input type="number" value="" v-model="fee_time" @focus="getFocus('fee_time')"
					@blur="edit('fee_time')" />
				<text>分钟</text>
				<input type="number" value="" v-model="fee_money" @focus="getFocus('fee_money')"
					@blur="edit('fee_money')" />
				<text>元</text>
			</view>

		</view>


		<view class="list">
			<view class="list_item">
				<view class="left">
					电池数量
				</view>
				<view class="right">
					<!-- <text>{{battery_num}}</text>
					<image src="/static/img/detail/right.png" mode="widthFix"></image> -->
					<input type="number" value="" v-model="battery_num" @focus="getFocus('battery_num')" :disabled="true"
						@blur="edit('battery_num')" />
				</view>
			</view>
			<view class="list_item">
				<view class="left">
					浮板数量
				</view>
				<view class="right">
					<!-- <text>{{fuban_num}}</text>
					<image src="/static/img/detail/right.png" mode="widthFix"></image> -->
					<input type="number" value="" v-model="fuban_num" @focus="getFocus('fuban_num')" :disabled="true"
						@blur="edit('fuban_num')" />
				</view>
			</view>
		</view>

		<view class="list">
			<view class="list_item">
				<view class="left">
					地址
				</view>
				<view class="right" @click="showAddress">
					{{ places.length ? places.join('-') : '请选择地点'}}
				</view>
			</view>
			<view class="list_item">
				<view class="left">
					详细地址
				</view>
				<view class="right" style="width: 70%;text-align: right">
					<!-- <text>{{address}}</text>
					<image src="/static/img/detail/right.png" mode="widthFix"></image> -->
					<text class="duohangText" type="text"  @focus="getFocus('address')" style="width: 100%;"
					      @blur="edit('address')">{{address}}</text>
				</view>
			</view>
			<!-- <view class="list_item" @click="account">
				<view class="left">
					分账
				</view>
				<view class="right">
					<image src="/static/img/detail/right.png" mode="widthFix"></image>
				</view>
			</view> -->
			<view class="list_item" @click="toBattery">
				<view class="left">
					电池使用状态
				</view>
				<view class="right">
					<image src="/static/img/detail/right.png" mode="widthFix"></image>
				</view>
			</view>
		</view>
		<jc-address-picker :level='level' :places='places' :visible.sync='visible' @change='change'></jc-address-picker>
		<!-- <view class="bottom">
			<view class="tit">
				<text>电池名</text>
				<text>状态</text>
				<text>当前状态</text>
				<text>人次</text>
				<text class="last">时间/分</text>
			</view>

			<view class="content" v-for="(item,index) in list" :key='index'>
				<text>{{item.item_code}}</text>
				<text v-if="item.item_state == 1" class="on-line">{{item.item_state_text}}</text>
				<text v-if="item.item_state == 0" class="off-line">{{item.item_state_text}}</text>
				<text v-if="item.use_state==1" class="off-line">{{item.curr_state_text}}</text>
				<text v-if="item.use_state==0" class="on-line">{{item.curr_state_text}}</text>
				<text>{{item.num}}</text>
				<text>{{item.time_len}}</text>
			</view>

		</view> -->


	</view>
</template>

<script>
	import jcAddressPicker from '@/components/jc-address-picker/jc-address-picker.vue'
	import {
		getDevice,
		editDevice
	} from '../../../api/api.js'
	export default {
		components: {
			jcAddressPicker
		},
		data() {
			return {
				places: [],
				level: 3,
				visible: false,
				ischeck: false,
				device_id: '',
				code: '',
				state_text: '',
				online_time_date: '',
				all_income: '',
				help_phone: '',
				address: '',
				name: '',
				free_time: '',
				fee_money: '',
				fee_time: '',
				battery_num: '',
				fuban_num: '',
				id: '',
				save: '',
				fee_first_time: '',
				fee_first_money: ''
				// list: []
			}
		},
		onLoad(options) {
			this.device_id = options.id
			this.getInfo()
		},
		methods: {
			getInfo() {
				getDevice({
					code: this.device_id
				}).then(res => {
					console.log(res)
					this.code = res.data.code
					this.id = res.data.device_id
					this.all_income = res.data.all_income
					this.address = res.data.address
					this.help_phone = res.data.help_phone
					this.state_text = res.data.state_text
					this.online_time_date = res.data.create_text
					this.name = res.data.name
					this.free_time = res.data.free_time
					this.fee_money = res.data.fee_money
					this.fee_first_time = res.data.fee_first_time
					this.fee_first_money = res.data.fee_first_money
					this.fee_time = res.data.fee_time
					this.battery_num = res.data.battery_num
					this.fuban_num = res.data.fuban_num
					this.places = res.data.area_text.split('/');
					// this.places.push(res.data.city)
					// this.places.push(res.data.area)
				})
			},
			editAdd() {
				uni.navigateTo({
					url: '/pages/agent/index/address'
				})
			},
			isChange() {
				this.ischeck = !this.ischeck
			},
			showAddress() {
				this.visible = true;
			},
			getFocus(name) {
				this.save = this[name]
				this[name] = ''
			},
			edit(name) {
				if (this[name] == '') {
					this[name] = this.save
					return
				}
				editDevice({
					code: this.code,
					address: this.address,
					name: this.name,
					free_time: this.free_time,
					fee_time: this.fee_time,
					fee_money: this.fee_money,
					fuban_num: this.fuban_num,
					battery_num: this.battery_num,
					province: this.places[0],
					city: this.places[1],
					area: this.places[2],
				}).then(res => {
					console.log(res)
				})
			},
			change(data) {
				this.places = data.map(i => i.name);
				this.edit()
			},
			toBattery() {
				uni.navigateTo({
					url: '/pages/agent/index/battery?device_id=' + this.id
				})
			},
			account() {
				uni.navigateTo({
					url: '/pages/agent/index/account?device_id=' + this.id
				})
			}
		},
	}
</script>

<style scoped lang="scss">
	.container {
		width: 100%;
		padding-top: 30upx;
		background-color: #f6f6f6;
	}

	.list {
		width: 100%;
		background-color: #FFFFFF;
		margin-top: 20upx;

		.list_item {
			width: calc(100% - 60upx);
			height: 90upx;
			padding: 10upx 0;
			margin: 0 auto;
			border-bottom: 1upx solid #e9e6e9;
			display: flex;
			justify-content: space-between;
			align-items: center;

			.left {
				text {
					font-size: 24upx;
					color: #999;
				}
			}

			.right {
				display: flex;
				align-items: center;
				color: #999999;

				input {
					min-width: 250upx;
					text-align: right;
					margin-right: 10upx;
				}

				text {
					font-size: 28upx;
				}

				image {
					width: 15upx;
					margin-left: 10upx;
				}

				view {
					font-size: 28upx;
					color: #999999;

					view {
						height: 56upx;
						line-height: 56upx;
						text-align: right;
					}
				}
			}

			.img {
				image {
					width: 40upx;
				}
			}
		}

	}

	.list:first-child {
		margin-top: 0;
	}

	.bottom {
		width: calc(100%);
		min-height: 300upx;
		padding: 0 30upx;
		background-color: #FFFFFF;

		.tit {
			padding: 30upx 0;
			display: flex;
			align-items: center;
			justify-content: space-between;

			text {
				width: 20%;
				// padding: 0 26upx;
				text-align: center;
				// border-right: 2upx solid #c1c1c1;
			}

			.last {
				border: 0;
			}

		}

		.content {
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-top: 10upx;


			text {
				width: 20%;
				color: #999999;
				padding: 0 15upx;
				text-align: center;
			}

			.on-line {
				color: #3bdbbe;
			}

			.off-line {
				color: #ffb6b3;
			}

		}
	}

	.new_item {
		width: calc(100% - 60upx);
		height: 100upx;
		background-color: #FFFFFF;
		margin: 0 auto;
		display: flex;
		align-items: center;
		border-bottom: 1upx solid #e9e6e9;
		position: relative;

		input {
			width: 100upx;
			height: 100%;
			margin-left: 30upx;
		}

		text {
			min-width: 120upx;
		}

		image {
			position: absolute;
			top: 35upx;
			right: 30upx;
			width: 30upx;
		}
	}

	// 2021-1-29
	.news {
		margin-top: 20upx;

		.news_tip {
			font-size: 24upx;
			color: #999;
			padding: 20upx 30upx;
			background-color: #f6f6f6;
		}

		.new_item {
			text {
				min-width: 30upx;
				text-align: left;
				padding-left: 30upx;
			}
		}
	}
	.duohangText{
		display: -webkit-box;
		-webkit-line-clamp: 3;
		-webkit-box-orient: vertical;
		overflow: hidden;
		text-overflow: ellipsis;
		max-height: 4.5em; /* 行高1.5em的3行 */
		line-height: 1.5em;
	}
</style>
